#include <QMap>
#include "zookeper.h"
#include "being.h"
#include <QGraphicsScene>
#include "hexitem.h"

ZooKeeper::ZooKeeper(QGraphicsScene *s, HexItem ***_hexItems) //ZooKeeper(Kutt *kutt)
{
    scene = s;
    this->hexItems = _hexItems;
    beings = new QMap<int,Being*>();
    //this->kutt = kutt;
}

ZooKeeper::~ZooKeeper()
{
    beings->clear(); // according to reference, this calls elements' destructors
    delete beings;
}

void ZooKeeper::welcome(int Type, int Id, int X, int Y, int SW, int MW, int W, int Speed)
{
    HexItem* HI = hexItems[X][Y];
    Being *being = new Being(Type, X, Y, SW, MW, W, Speed,HI->h);
    scene->addItem(being);
    being->setPos(HI->pos());
    being->show();
    //kutt.kuttuj(being);
    (*beings)[Id] = being;
}

void ZooKeeper::goodbye(int Id)
{
    Being *being = (*beings)[Id];
    //kutt.wykuttuj(being);
    scene->removeItem(being);
    beings->remove(Id);
    //delete being;// according to reference, this calls element's destructor
}

void ZooKeeper::feed(int Id, int Val)
{
    (*beings)[Id]->weight = Val;
}

void ZooKeeper::move(int Id, int X, int Y)
{
    (*beings)[Id]->X = X;
    (*beings)[Id]->Y = Y;
    (*beings)[Id]->setPos((hexItems[X][Y])->pos());
}
